package models;

import java.util.LinkedList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import play.db.jpa.Model;

@Entity

public class Course extends Model{
	
	public String name;
	public String description;
	public String code;
	
	public static final int BASIC = 1; 
	public static final int TRINITY = 2;
	
	public double price;
	public String level;
	public byte type;

	public boolean isHidden;
	
	@ManyToOne
	public Activity activity;
	
			
	@OneToMany(mappedBy = "course",cascade= CascadeType.ALL)
	public List<Register> registrations;

	public Course(String name, String description, double price,
			String level, byte type, Activity activity) {
		
		this.name = name;
		this.description = description;
		this.price = price;
		this.level = level;
		this.type = type;
		this.activity = activity;
				
		
	}
	
	public void setCode() {
		if(!activity.teachers.isEmpty())
		code = "#"+activity.teachers.get(0).id+activity.id+id;
		
	}
	public String getType() {
		
		switch(type){
		
		case 1 : return "Basic";
		default : return "Trinity";
		
		}
	}

	public List<Class> getCourseClasses() {
		
		LinkedList<Class> classes = new LinkedList<Class>();
		
		for(int i=0 ; i<registrations.size(); i++){
			classes.addAll(registrations.get(i).sClass);
		}
		
		return classes;
	
	}
	
	
	
}
